import { createStore } from "vuex";

export default createStore({
  state: {
    shopcar: [],
  },
  mutations: {
    add(state, obj) {
      let flag = false;
      state.shopcar.forEach((item) => {
        if (item.id == obj.id) {
          flag = true;
          item.num += obj.num;
        }
      });

      if (flag == false) {
        obj.status = false;
        //新添加一个字段 状态是未选中的
        state.shopcar.push(obj);
      }
    },
  },
  actions: {},
  modules: {},
});
